/**
 * 功能:发票代码号码范围 Service类
 * 开发人员:yaren
 * 创建时间:2012/4/21 22:45:40
 */
package com.towker.frame.service.basicData;

import org.springframework.stereotype.Service;
import com.towker.core.db.EntityDao;
import com.towker.core.db.BaseService;
import com.towker.frame.model.basicData.Invoices;
import com.towker.frame.dao.basicData.InvoicesDao;

@Service
public class InvoicesService extends BaseService<Invoices, java.lang.Long>
{
	private InvoicesDao dao;
	
	public void setInvoicesDao(InvoicesDao dao)
	{
		this.dao = dao;
	}

	@SuppressWarnings("unchecked")
	@Override
	protected EntityDao getEntityDao()
	{
		return this.dao;
	}
	
	public Invoices getByBillingCode(String billingCode) {
		return this.dao.getByBillingCode(billingCode);
	}
	
	public int getNextInvoiceNum(String billingCode) {
		Invoices invoices = getByBillingCode(billingCode);
		if (invoices == null) {
			return 0;
		} else {
			if (invoices.getEnd_id() <= invoices.getCurrent_id()) {
				return 0;
			} else {
				invoices.setCurrent_id(invoices.getCurrent_id() + 1);
				update(invoices);
				return invoices.getCurrent_id();
			}
		}
	}
}
